<?php defined('_JEXEC') or die('Restricted access'); 
$session = JSession::getInstance('none',array());
if(!isset($_REQUEST['columns']))
{
    if ($session->has('columns')) {
        $columns = $session->get('columns');
	} else {	
	    $_REQUEST['columns'] = 'ticket,summary,status,owner,type,priority,component,milestone';
	    $columns = explode(',',$_REQUEST['columns']);
	}
}else{
	$columns = $_REQUEST['columns'];
}
$session->set('columns', $columns);


?>
<?php
echo JhtraqHelper::drawTabs($this->project->slug);
?>
<p></p>
<div class="componentheading">
	<?php echo $this->project->name; ?> - <?php echo JText::_('COM_JHTRAQ_TICKETS');?>
</div>

<form action="" method="post">
	<fieldset id="ticket_columns">
		<legend><?php echo JText::_('COM_JHTRAQ_DISPLAY')?></legend>
		<?php foreach($this->ticket_columns() as $column) { ?>
		<input type="checkbox" name="columns[]" value="<?php echo $column?>" id="col_<?php echo $column?>"<?php if(in_array($column,$columns)) echo ' checked="checked"'?> /> <label for="col_<?php echo $column?>"><?php echo JText::_('COM_JHTRAQ_'. strtoupper($column))?></label>
		<?php } ?>
		
	</fieldset>
	<fieldset id="ticket_filters">
	<legend><?php echo JText::_('COM_JHTRAQ_FILTER');?></legend>
	<table width="100%">
	<tr>
		<td width="13%">
		<label for="status"><?php echo JText::_('COM_JHTRAQ_STATUS');?></label>
		</td>
		<td width="20%">
			<select name="filter[status]">
			<option value=""><?php echo JText::_('COM_JHTRAQ_ALL');?></option>
			<?php $this->buildOptions('status'); ?>
			</select>
		</td>
		<td width="13%">
			<label for="type"><?php echo JText::_('COM_JHTRAQ_TYPE');?></label>
		</td>
		<td width="20%">
			<select name="filter[type]">
			<option value=""><?php echo JText::_('COM_JHTRAQ_ALL');?></option>
			<?php $this->buildOptions('type'); ?>
			</select>
		</td>
		<td width="13%">
		<label for="type"><?php echo JText::_('COM_JHTRAQ_SEVERITY');?></label>
		</td>
		<td width="21%">
			<select name="filter[severity]">
			<option value=""><?php echo JText::_('COM_JHTRAQ_ALL');?></option>
			<?php $this->buildOptions('severity'); ?>
			</select>
		</td>
	</tr>
	<tr>
		<td>
		<label for="type"><?php echo JText::_('COM_JHTRAQ_PRIORITY');?></label>
		</td>
		<td>
			<select name="filter[priority]">
			<option value=""><?php echo JText::_('COM_JHTRAQ_ALL');?></option>
			<?php $this->buildOptions('priority'); ?>
			</select>
		</td>
		<td>
		<label for="type"><?php echo JText::_('COM_JHTRAQ_MILESTONE');?></label>
		</td>
		<td>
			<select name="filter[milestone_id]">
			<option value=""><?php echo JText::_('COM_JHTRAQ_ALL');?></option>
			<?php $this->buildOptions('milestone_id',$this->project->id); ?>
			</select>
		</td>
		<td>
		<label for="type"><?php echo JText::_('COM_JHTRAQ_VERSION');?></label>
		</td>
		<td>
			<select name="filter[version_id]">
			<option value=""><?php echo JText::_('COM_JHTRAQ_ALL');?></option>
			<?php $this->buildOptions('version_id',$this->project->id); ?>
			</select>
		</td>
	</tr>
	<tr>
	<td colspan="6" >
	<?php
	if($this->completed)
	{
		?>
		<?php echo JText::_("COM_JHTRAQ_HIDE_CLOSED_TICKETS");?><input type="checkbox" value="1" name="completed" />
		<?php
	}else{
		?>
		<?php echo JText::_("COM_JHTRAQ_SHOW_CLOSED_TICKETS");?><input type="checkbox" value="1" name="completed" />
		<?php
	}
	?>
	
	</td>
	</tr>
	</table>
	</fieldset>
	<div style="float:right">
	<input type="submit" value="<?php echo JText::_('COM_JHTRAQ_UPDATE')?>" />
	</div>
</form>

<table class="contentpane listing tickets" width="100%">
			<thead>
				<tr class="sectiontableheader">
				<?php if(in_array('ticket',$columns)) { ?><td class="sectiontableheader"><?php echo JText::_('COM_JHTRAQ_TICKET')?></th><?php } ?>
				<?php if(in_array('summary',$columns)) { ?><td class="sectiontableheader"><?php echo JText::_('COM_JHTRAQ_SUMMARY')?></th><?php } ?>
				<?php if(in_array('status',$columns)) { ?><td class="sectiontableheader"><?php echo JText::_('COM_JHTRAQ_STATUS')?></th><?php } ?>
				<?php if(in_array('owner',$columns)) { ?><td class="sectiontableheader"><?php echo JText::_('COM_JHTRAQ_OWNER')?></th><?php } ?>
				<?php if(in_array('type',$columns)) { ?><td class="sectiontableheader"><?php echo JText::_('COM_JHTRAQ_TYPE')?></th><?php } ?>
				<?php if(in_array('severity',$columns)) { ?><td class="sectiontableheader"><?php echo JText::_('COM_JHTRAQ_SEVERITY')?> </th><?php } ?>
				<?php if(in_array('component',$columns)) { ?><td class="sectiontableheader"><?php echo JText::_('COM_JHTRAQ_COMPONENT')?></th><?php } ?>
				<?php if(in_array('milestone',$columns)) { ?><td class="sectiontableheader"><?php echo JText::_('COM_JHTRAQ_MILESTONE')?></th><?php } ?>
				<?php if(in_array('version',$columns)) { ?><td class="sectiontableheader"><?php echo JText::_('COM_JHTRAQ_VERSION')?></th><?php } ?>
				<?php if(in_array('assigned_to',$columns)) { ?><td class="sectiontableheader"><?php echo JText::_('COM_JHTRAQ_ASSIGNED_TO')?></th><?php } ?>
				</tr>
			</thead>
			<tbody>
				   <?php
				foreach($this->tickets as $ticket) { ?>
				<tr class="priority<?php echo $ticket['priority']?>">
				<?php if(in_array('ticket',$columns)) { ?><td class="id"><a href="<?php echo JRoute::_("index.php?option=com_jhtraq&view=tickets&layout=view&project=".$this->project->slug."&ticket=".$ticket['ticket_id'])?>"><?php echo $ticket['ticket_id']?></a></td><?php } ?>
				<?php if(in_array('summary',$columns)) { ?><td><a href="<?php echo JRoute::_("index.php?option=com_jhtraq&view=tickets&layout=view&project=".$this->project->slug."&ticket=".$ticket['ticket_id'])?>"><?php echo $ticket['summary']?></a></td><?php } ?>
				<?php if(in_array('status',$columns)) { ?><td><?php echo $this->ticket_status($ticket['status'])?></td><?php } ?>
				<?php if(in_array('owner',$columns)) { ?><td><?php echo $ticket['user_name']?></td><?php } ?>
				<?php if(in_array('type',$columns)) { ?><td><?php echo $this->ticket_type($ticket['type'])?></td><?php } ?>
				<?php if(in_array('severity',$columns)) { ?><td><?php echo $this->ticket_severity($ticket['severity'])?></td><?php } ?>
				<?php if(in_array('component',$columns)) { ?><td><?php echo $ticket['component']['name']?></td><?php } ?>
				<?php if(in_array('milestone',$columns)) { ?><td><?php echo $ticket['milestone']['milestone']?></td><?php } ?>
				<?php if(in_array('version',$columns)) { ?><td><?php echo $ticket['version']['version']?></td><?php } ?>
				<?php if(in_array('assigned_to',$columns)) { ?><td><?php echo $ticket['assignee']['username']?></td><?php } ?>
				</tr>
				<?php } ?>
				<tr class="sectiontablefooter">
					<td class="sectiontablefooter" align="center" colspan="<?php echo count($columns);?>" nobr>
					<?php echo $this->pagination->getPagesLinks();?></td>
				</tr>
			</tbody>
		</table>